<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>ansible判断 出现FATAL all hosts have already failed -- aborting 错误 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>ansible判断 出现FATAL all hosts have already failed -- aborting 错误</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Ansible/">Ansible</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;今晚做ansible实验，验证到when判断ip的时候，遇到了个问题，就是使用ansible 127.0.0.1 -m setup 显示出来的内容并不像视频里面所显示的那样，每个值都以facter_开头的；也更找不到facter_ipaddress这个值，就是说使用facts ip判断条件是不能使用的？效果如下截图：</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/ansible%E5%88%A4%E6%96%AD%20%E5%87%BA%E7%8E%B0FATAL%20all%20hosts%20have%20already%20failed%20--%20aborting%20%E9%94%99%E8%AF%AF/01.jpeg?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后去谷歌搜索了下，发现也不少人也遇到这个问题得不到解决。看了那些大神回复根本看不懂，还有个使用Python把值提取出来的，但是不懂Python，好无奈。。。。只能自己想办法了。   </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;最初试验的代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">---</div><div class="line">- hosts: testhosts</div><div class="line">  remote_user: root</div><div class="line">  gather_facts: True</div><div class="line">  tasks:</div><div class="line">    - shell: touch /tmp/when.txt</div><div class="line">      when: facter_ipaddress==<span class="string">"192.168.0.82"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决方案代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">---</div><div class="line">- hosts: testhosts</div><div class="line">  remote_user: root</div><div class="line">  gather_facts: True</div><div class="line">  tasks:</div><div class="line">    - shell: touch /tmp/when.txt</div><div class="line">      when: ansible_eth0.ipv4.address==<span class="string">"192.168.0.82"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;只是 facter_ipaddress变成了ansible_eth0.ipv4.address；至于为什么这样变？ ansible X.X.X.X -m setup 探索一下就知道了。</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/ansible%E5%88%A4%E6%96%AD%20%E5%87%BA%E7%8E%B0FATAL%20all%20hosts%20have%20already%20failed%20--%20aborting%20%E9%94%99%E8%AF%AF/02.png?raw=true" alt=""></figure></p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Ansible/2. ansible判断 出现FATAL all hosts have already failed -- aborting 错误/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
